ThinkPHP6.0 门面 您所在的位置:网站首页 think think app ThinkPHP6.0 门面

ThinkPHP6.0 门面

2023-01-12 17:00| 来源: 网络整理| 查看: 265

系统给常用类库定义了Facade类库,具体如下:

(动态)类库 Facade类 think\App think\facade\App think\Cache think\facade\Cache think\Config think\facade\Config think\Cookie think\facade\Cookie think\Db think\facade\Db think\Env think\facade\Env think\Event think\facade\Event think\Filesystem think\facade\Filesystem think\Lang think\facade\Lang think\Log think\facade\Log think\Middleware think\facade\Middleware think\Request think\facade\Request think\Response think\facade\Response think\Route think\facade\Route think\Session think\facade\Session think\Validate think\facade\Validate think\View think\facade\View

无需进行实例化就可以很方便的进行方法调用:

namespace app\index\controller; use think\facade\Cache; class Index { public function index() { Cache::set('name','value'); echo Cache::get('name'); } }

在进行依赖注入的时候,请不要使用 Facade 类作为类型约束,而使用原来的动态类。

事实上,依赖注入和使用 Facade 的效果大多数情况下是一样的,都是从容器中获取对象实例。

以下两种的作用一样,但是引用的类库却不一样

// 依赖注入 namespace app\index\controller; use think\Request; class Index { public function index(Request $request) { echo $request->controller(); } } // 门面模式 namespace app\index\controller; use think\facade\Request; class Index { public function index() { echo Request::controller(); } }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有